﻿$(document).ready(function() {
	getDocList();
});
function getDocList(){
	var url = foxit.common.path + '/ListFile.do';
	var pagePanel='#pager';
	var result='#doclist';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	foxit.common.changePage(url,pageSize,result,fn_getDocList,pagePanel,defaultHtml);
}
function deletePdf(id, docName, version) {

	if (confirm("是否确认要进行删除？")) {
		$.post(foxit.common.path + '/DelFile.do', {
			docName : docName,
			id : id,
			//parentid : parentid,
			version : version
		}, function(data) {
			if (!data.root) {
				alert("delete file error! please try again!");
			} else {
				getDocList();//刷新
				//handlePdfHistory(id, title);
			}
		}, 'json');
	}
}

function fn_getDocList(obj,result,i){
	var str ='';
	console.log(obj);
	str+='<div class="row_top_content">';
	str+='<div class="content">'+obj.DOC_NAME+'</div>';
    str+='<div class="content">'+obj.DOC_SIZE+'</div>';
    str+='<div class="content">'+obj.USER+'</div>';
    str+='<div class="content">'+obj.CREATETIME2+'</div>';
    str+='<div class="content">';
    var path = foxit.common.path + '/LoadReader.do?fileid=' + obj.PK_PDF_DOC;
	str+='<input name="ck" type="button" class="button01" onclick="window.location.href = (\' ' + path + '\')" value="查看"/>&nbsp;';
	//str+='<input name="xg" type="button" class="button01" onclick="window.open(\'editor.html?PK_PDF_DOC='+obj.PK_PDF_DOC+'\')" value="编辑"/>&nbsp;';
	//str+='<input name="ls" type="button" class="button07" onclick="getHistoryDocList('+obj.PK_PDF_DOC+')" value="历史记录"/>&nbsp;';
	//var docPath=obj.PDF_URL;
	//str+='<input name="del" type="button" class="button01" onclick="downloadPdf2(\''+docPath+'\',\''+obj.DOC_TITLE+'\')" value="下载"/>';
	str+='<input name="del" type="button" class="button01" onclick="deletePdf(\''+obj.PK_PDF_DOC+'\',\''+obj.DOC_NAME+'\',\''+obj.DOC_VERSION+'\')" value="删除"/>';
       
    str+='</div>';
    str+='</div>';
	$(result).append(str);
}
//下载
function downloadPdf2(doc_src, title) {
	 window.location.href = foxit.common.path + "/upload/down/do_Down.jsp?path="+doc_src+"&title="+title;
}
function getHistoryDocList(objId){
	$('#historyDiv').show();
	var url = foxit.common.path + '/queryPdfDocAction.action?PK_PDF_DOC='+objId;
	var pagePanel='#pager2';
	var result='#doclist2';
	var pageSize=10;
	var defaultHtml='<li><em style="text-align: center;width:100%">没有搜索到您要查询的数据...</em></li>';
	foxit.common.changePage(url,pageSize,result,fn_getHistoryDocList,pagePanel,defaultHtml);
}


function fn_getHistoryDocList(obj,result,i){
	var str ='';
	str+='<li>';
	str+='<div class="content">'+obj.DOC_NAME+'</div>';
    str+='<div class="content">'+obj.DOC_SIZE+'</div>';
    str+='<div class="content">'+obj.USER+'</div>';
    str+='<div class="content">'+obj.CREATETIME2+'</div>';
    str+='<em class="bfb25">';
    
    var path = foxit.common.path + '/LoadReader.do?fileid=' + obj.PK_PDF_DOC;
	str+='<input name="ck" type="button" class="button01" onclick="window.location.href = (\' ' + path + '\')" value="查看"/>&nbsp;';
	str+='<input name="xg" type="button" class="button01" onclick="window.open(\'editor.html?PK_PDF_DOC='+obj.PK_PDF_DOC+'\')" value="编辑"/>&nbsp;';
	str+='<input name="del" type="button" class="button01" onclick="downLoadPdf('+obj.PK_PDF_DOC+')" value="下载"/>';
       
    str+='</em>';
    str+='</li>';
	$(result).append(str);
}